"""
交易 - 退款服务
"""

from jlpay.services.base_service import BaseService
from jlpay.model.trans.common.common_trans import RefundRequest, RefundResponse


class RefundService(BaseService):
    """退款服务"""
    
    def __init__(self, config):
        """
        初始化退款服务
        
        Args:
            config: OrgConfig实例
        """
        super().__init__(config)
    
    def get_api_url(self, request_class, api_path=None):
        """
        获取API URL
        
        Args:
            request_class: 请求类
            api_path: 接口路径
            
        Returns:
            完整的API URL
        """
        base_url = self.config.url
        
        if api_path:
            return f"{base_url}{api_path}"
        
        # 直接使用Request类中定义的API_URL
        api_url = getattr(request_class, 'API_URL', '')
        if api_url:
            return f"{base_url}{api_url}"
        
        # 如果没有定义API_URL，使用默认路径
        return f"{base_url}/open/trans"
    
    def refund(self, request):
        """
        退款接口
        
        Args:
            request: RefundRequest实例
            
        Returns:
            RefundResponse实例
        """
        return self.post(request, RefundResponse) 